package com.sudichina.sudichina.view.activity.main;

import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.services.core.LatLonPoint;
import com.google.gson.reflect.TypeToken;
import com.sudichina.sudichina.Contains;
import com.sudichina.sudichina.MyApp;
import com.sudichina.sudichina.NET.Api;
import com.sudichina.sudichina.NET.NetUtils;
import com.sudichina.sudichina.NET.onRequestDataFinish;
import com.sudichina.sudichina.R;
import com.sudichina.sudichina.bean.Car;
import com.sudichina.sudichina.bean.Result;
import com.sudichina.sudichina.bean.User;
import com.sudichina.sudichina.choosecity.CityPickerActivity;
import com.sudichina.sudichina.entity.ReleaseRoute;
import com.sudichina.sudichina.utils.Toastutils;
import com.sudichina.sudichina.view.activity.HelpActivity;
import com.sudichina.sudichina.view.activity.LineManageActivity;
import com.sudichina.sudichina.view.activity.MessageActivity;
import com.sudichina.sudichina.view.activity.about.AboutUsActivity;
import com.sudichina.sudichina.view.activity.dentification.CarIdentificationActivity;
import com.sudichina.sudichina.view.activity.dentification.CarManagerActivity;
import com.sudichina.sudichina.view.activity.dentification.IdcardManagerActivity;
import com.sudichina.sudichina.view.activity.dentification.IdentificationActivity;
import com.sudichina.sudichina.view.activity.login.LoginActivity;
import com.sudichina.sudichina.view.activity.orlder.MyOrlderActivity;
import com.sudichina.sudichina.view.activity.qiangdan.QiangdanActivity;
import com.sudichina.sudichina.view.activity.setting.SettingActivity;
import com.sudichina.sudichina.view.activity.wallet.RechargeActivity;
import com.sudichina.sudichina.view.activity.wallet.WalletActivity;
import com.sudichina.sudichina.view.customview.RoundImageView;
import com.sudichina.sudichina.view.customview.xlistview.ListViewDialog;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 创建于2017年3月2号 晚上21:34 杨伟乔
 */

/**
 * 主界面
 */
public class MainActivity extends BaseActivity implements View.OnClickListener, NavigationView.OnNavigationItemSelectedListener, LocationSource, AMapLocationListener, onRequestDataFinish {
    @BindView(R.id.toolbar_title)
    TextView privateToolbarTitle;
    @BindView(R.id.btnRight)
    ImageView privateBtnRight;
    @BindView(R.id.toolbar)
    Toolbar privateToolbar;
    @BindView(R.id.map)
    MapView mapView;
    @BindView(R.id.et_chufadi)
    EditText privateEtChufadi;
    @BindView(R.id.et_mudidi)
    EditText privateEtMudidi;
    @BindView(R.id.del)
    ImageView privateDel;
    @BindView(R.id.tv_chepai)
    TextView tvChePai;
    @BindView(R.id.tv_mode)
    TextView tvMode;
    @BindView(R.id.times)
    TextView privateTimes;
    @BindView(R.id.btn_fabu)
    Button privateBtnFabu;
    @BindView(R.id.content_main)
    LinearLayout privateContentMain;
    @BindView(R.id.nav_view)
    NavigationView privateNavView;
    @BindView(R.id.drawer_layout)
    DrawerLayout privateDrawerLayout;
    @BindView(R.id.qiangdan)
    ImageView privateQiangdan;
    //地图的已经注解就叫mapView
    private MapView mMapView;

    //定位的
    private LocationSource.OnLocationChangedListener mListener;
    private AMapLocationClient mlocationClient;
    private AMapLocationClientOption mLocationOption;
    //点位到的地址
    private String address;
    //上下文
    private Context context;


    ListView listView;
    ArrayList<String> carList;
    ArrayList<String> modeList;
    TextView number;
    private boolean isIdentification = false;

    //申请key 需要得到  测试的 94:EF:6B:4B:16:6E:3C:96:7E:B6:B5:C5:02:8F:30:5D:22:D3:65:40
    //正式  01:24:A4:B6:53:F7:EF:F3:88:E3:DF:61:57:06:74:5B:BA:AB:87:97
    //高德使用到的变量
    private AMap aMap;
    private List<Car> cars;
    private String strCar = null;
    private String strMode = null;
    private String startday;
    private String dateOut;
    private List<Integer> carListID = new ArrayList();
    private List<Integer> carListDicID = new ArrayList();
    private int carId;
    private int carDicId;
    private Car car;
    private Intent intent1;


    /**
     * Long accountId; // 用户Id  直接获取
     * Long carId; // 车辆id  根据选择的车牌号码位置从集合里面取出来
     * Long dicId; // 车辆参数Id   集合里面取  保存为全局
     * Long toZoneCode; // 到达地区code
     * Long fromZoneCode; // 开始地区code
     * String laLoPosition; // 经度，纬度  直接定位位置传过去
     * <p>
     * String type; // 发布类型   传个"Android"
     * String fromAddress; // 起点，详细地址  获取起始地
     * <p>
     * <p>
     * Double priceDun; // 吨的单价
     * Double priceSquare; // 方的单价
     * Double priceKg; // 千克的单价
     * Double priceAll; // 整车价格
     * <p>
     * Double prickDoor; // 千克的单价
     * Double prickStation; // 整车价格
     * <p>
     * Date releaseTime; // 发车时间
     * Date arriveTime; // 到达时间
     */

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        context = this;
        number = (TextView) findViewById(R.id.number);
        //初始化view
        initView(savedInstanceState);


    }


    ArrayAdapter adapter;


    /**
     * 初始化控件
     *
     * @param savedInstanceState
     */
    private void initView(Bundle savedInstanceState) {
        //菜单和标题栏的处理方法
        manageMenu();
        //主界面显示地图的处理方法
        manageMain(savedInstanceState);


        modeList = new ArrayList();
        modeList.add("整车");
        modeList.add("零担");
        if (modeList != null) {
            tvMode.setText(modeList.get(0));
        }


        privateEtMudidi.setFocusable(false);
        privateEtChufadi.setFocusable(false);
        privateEtChufadi
                .setOnClickListener(this);
        privateEtMudidi.setOnClickListener(this);
    }


    /**
     * 菜单和标题栏的管理
     */
    private void manageMenu() {

        /*
        标题栏
         */
        //找到控件
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        TextView toolbar_title = (TextView) findViewById(R.id.toolbar_title);
        toolbar.setTitle("");
        //设置标题
        toolbar_title.setText("分通");
        //设置支持actionbar
        setSupportActionBar(toolbar);

        /**
         * 侧滑菜单
         */
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();


        /**
         * 菜单的条目点击事件
         */
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        //设置侧滑菜单上的文字样式
        Resources resource = (Resources) getBaseContext().getResources();
        ColorStateList csl = (ColorStateList) resource.getColorStateList(R.color.navigation_menu_item_color);

        navigationView.setItemTextColor(csl);
/**设置MenuItem默认选中项**/
        // navigationView.getMenu().getItem(0).setChecked(true);
        /**
         * 头像处理
         */

        View headerView = navigationView.getHeaderView(0);
        user_name = (TextView) headerView.findViewById(R.id.user_name);
        imageView = (RoundImageView) headerView.findViewById(R.id.imageView);
        user_name.setText("请登录..");

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

//                Toastutils.showToast("点击头像 判断用户是否登录 如果登录 直接显示个人信息界面 如果没有登录 显示的登录界面");
                if (currentUser == null) {
                    //跳转登录的界面
                    LoginActivity.startMeAndInitIsLogin(MainActivity.this, Contains.MAIN);
                }

            }
        });
    }

    TextView user_name;
    RoundImageView imageView;

    /**
     * 监听返回键  ;拦截返回键的原有方法 返回键一般按下时关闭当前的界面
     * 这里 我们先需要判断菜单是否是打开的
     * 如果打开 先关闭菜单 然后再次点击关闭界面
     */
    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        //判断当前的侧滑菜单是否为打开的状态
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            //如果是打开的状态  关闭菜单
            drawer.closeDrawer(GravityCompat.START);
        } else {
            //如果不是打开的状态 执行原来的效果
            exitBy2Click();
        }
    }


    /*双击退出函数*/
    private static Boolean isExit = false;

    private void exitBy2Click() {
        Timer timer = null;
        if (!isExit) {
            isExit = true; // 准备退出
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
            timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    isExit = false; // 取消退出
                }
            }, 2000); // 如果2秒钟内没有按下返回键，则启动定时器取消掉刚才执行的任务

        } else {
            finish();
        }
    }


    /*
    这个方法注意的是 点击菜单之后的关闭动作
    菜单的点击事件
     */
    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_order) {

            //我的订单
            intent = new Intent(this, MyOrlderActivity.class);
            startActivity(intent);

        } else if (id == R.id.nav_purse) {
            // 我的钱包
            intent = new Intent(this, WalletActivity.class);
            startActivity(intent);

        } else if (id == R.id.nav_identification) {
//认证验证
            intent = new Intent(this, IdcardManagerActivity.class);
            startActivity(intent);

        } else if (id == R.id.nav_youkachongzhi) {

            //油卡充值
            intent = new Intent(this, RechargeActivity.class);
            startActivity(intent);

        } else if (id == R.id.nav_busIdentification) {

            //车辆管理
            intent = new Intent(this, CarManagerActivity.class);
            startActivity(intent);
        } else if (id == R.id.nav_linemanage) {

            //线路管理
            intent = new Intent(this, LineManageActivity.class);
            startActivity(intent);
        } else if (id == R.id.nav_help) {

            //帮助中心
            intent = new Intent(this, HelpActivity.class);
            startActivity(intent);

        } else if (id == R.id.nav_aboutme) {

            //关于我们
            intent = new Intent(this, AboutUsActivity.class);
            startActivity(intent);

        } else if (id == R.id.nav_setting) {

            //设置中心
            intent = new Intent(this, SettingActivity.class);
            startActivity(intent);

        }


        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    private User currentUser;

    /**
     * 初始化数据
     */
    private void initDatas() {

        carList = new ArrayList<>();
        //判断当前的用户是否登录
        currentUser = new MyApp().getCurrentUser();
        if (null == currentUser) {
            //当前的用户没有登录
            user_name.setText("请登陆.");
            privateBtnFabu.setText("前往登陆");
            carList.clear();
            carList.add("没有认证车辆");
            if (carList != null) {
                tvChePai.setText(carList.get(0));
            }
//            setCarListSpinner();
        } else {
            //用户已经登录
            user_name.setText(currentUser.getAccountName());
            id = String.valueOf(MyApp.getCurrentUser().getId());
            // TODO: 2017/3/15 要挂问题就在这里
            Type type = new TypeToken<Result<List<Car>>>() {
            }.getType();
            NetUtils.requestData(Api.CARLISTBYSTATUS + id, null, this, type, true);
        }
    }

    private String id;
    MyLocationStyle myLocationStyle;

    /**
     * 地图处理的业务
     *
     * @param savedInstanceState
     */
    private void manageMain(Bundle savedInstanceState) {
//获取地图控件引用

        mMapView = (MapView) findViewById(R.id.map);
        //在activity执行onCreate时执行mMapView.onCreate(savedInstanceState)，创建地图
        mMapView.onCreate(savedInstanceState);
//初始化地图控制器


        if (aMap == null) {
            aMap = mMapView.getMap();
        }
        //去掉默认的缩放控件
        aMap.getUiSettings().setZoomControlsEnabled(false);
//添加指南针
        //添加指南针
        // aMap.getUiSettings().setCompassEnabled(true);
        aMap.getUiSettings().setMyLocationButtonEnabled(true);

        /*
        定位
         */
        // 设置定位监听
        aMap.setLocationSource(this);


        myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类
        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点，定位点依照设备方向旋转，并且会跟随设备移动。（1秒1次定位）如果不设置myLocationType，默认也会执行此种模式。
        myLocationStyle.interval(2000); //设置连续定位模式下的定位间隔，只在连续定位模式下生效，单次定位模式下不会生效。单位为毫秒。
        aMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style


// 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
        aMap.setMyLocationEnabled(true);
// 设置定位的类型为定位模式，有定位、跟随或地图根据面向方向旋转几种
        aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);

        aMap.setOnMapClickListener(new AMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                Toastutils.showToast("点击地图的坐标点是:" + latLng);


                LatLonPoint lp = new LatLonPoint(latLng.latitude, latLng.longitude);


            }


        });


    }


    /**
     * 激活定位
     *
     * @param listener
     */
    @Override
    public void activate(OnLocationChangedListener listener) {
        mListener = listener;
        if (mlocationClient == null) {
            //初始化定位
            mlocationClient = new AMapLocationClient(this);
            //初始化定位参数
            mLocationOption = new AMapLocationClientOption();
            //设置定位回调监听
            mlocationClient.setLocationListener(this);
            //设置为高精度定位模式
            mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);

            //设置定位参数
            mlocationClient.setLocationOption(mLocationOption);
            // 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
            // 注意设置合适的定位时间的间隔（最小间隔支持为2000ms），并且在合适时间调用stopLocation()方法来取消定位请求
            // 在定位结束后，在合适的生命周期调用onDestroy()方法
            // 在单次定位情况下，定位无论成功与否，都无需调用stopLocation()方法移除请求，定位sdk内部会移除
            mlocationClient.startLocation();//启动定位


        }
    }

    /**
     * 停止定位
     */
    @Override
    public void deactivate() {
        mListener = null;
        if (mlocationClient != null) {
            mlocationClient.stopLocation();
            mlocationClient.onDestroy();
        }
        mlocationClient = null;
    }

    /**
     * 定位改变
     * 定位成功后回调函数
     */

    @Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (mListener != null && amapLocation != null) {
            if (amapLocation != null
                    && amapLocation.getErrorCode() == 0) {
                mListener.onLocationChanged(amapLocation);// 显示系统小蓝点

                address = amapLocation.getCity() + amapLocation.getDistrict() + amapLocation.getAoiName();

                privateEtChufadi.setText(address);
                fromaddress = amapLocation.getCity() + amapLocation.getDistrict() ;
                cityCode = amapLocation.getAdCode();

                System.out.println("地图:" +

                        amapLocation.getLatitude() +//获取纬度
                        amapLocation.getLongitude() +//获取经度
                        amapLocation.getCountry() +//国家信息
                        amapLocation.getProvince() +//省信息
                        amapLocation.getCity() +//城市信息
                        amapLocation.getDistrict() +//城区信息
                        amapLocation.getStreet() + "//街道信息" +
                        amapLocation.getStreetNum() + "//街道门牌号信息" +
                        amapLocation.getCityCode() + "//城市编码" +

                        amapLocation.getAdCode() + "//地区编码" +
                        amapLocation.getAoiName() + "//获取当前定位点的AOI信息" +
                        amapLocation.getPoiName() +
                        amapLocation.getBuildingId() + "//获取当前室内定位的建筑物Id" +
                        amapLocation.getFloor()//获取当前室内定位的楼层

                );
                // 如果不设置标志位，此时再拖动地图时，它会不断将地图移动到当前的位置

                aMap.moveCamera(CameraUpdateFactory.zoomTo(15));
                //将地图移动到定位点
                aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude())));
                //点击定位按钮 能够将地图的中心移动到定位点
                mListener.onLocationChanged(amapLocation);
                //添加图钉
                aMap.addMarker(getMarkerOptions(amapLocation));
                //获取定位信息
                StringBuffer buffer = new StringBuffer();
                buffer.append(amapLocation.getCountry() + "" + amapLocation.getProvince() + "" + amapLocation.getCity() + "" + amapLocation.getProvince() + "" + amapLocation.getDistrict() + "" + amapLocation.getStreet() + "" + amapLocation.getStreetNum());
                Toast.makeText(getApplicationContext(), buffer.toString(), Toast.LENGTH_LONG).show();


                mlocationClient.stopLocation();
                aMap.moveCamera(CameraUpdateFactory.zoomTo(15));
            } else {
                String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
                Log.e("AmapErr", errText);
            }
        }
    }


    //自定义一个图钉，并且设置图标，当我们点击图钉时，显示设置的信息
    private MarkerOptions getMarkerOptions(AMapLocation amapLocation) {
        //设置图钉选项
        MarkerOptions options = new MarkerOptions();
        //图标
        options.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_back));
        //位置
        options.position(new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude()));
        StringBuffer buffer = new StringBuffer();
        buffer.append(amapLocation.getCountry() + "" + amapLocation.getProvince() + "" + amapLocation.getCity() + "" + amapLocation.getDistrict() + "" + amapLocation.getStreet() + "" + amapLocation.getStreetNum());
        //标题
        options.title(buffer.toString());
        //子标题
        options.snippet("这里好火");
        //设置多少帧刷新一次图片资源
        options.period(60);

        return options;

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        mMapView.onDestroy();


    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图

        //初始化数据
        initDatas();


        mMapView.onResume();


    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mMapView.onPause();


    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mMapView.onSaveInstanceState(outState);
    }

    ReleaseRoute releaseRoute = new ReleaseRoute();
    private String cityCode;
    private String fromaddress;

    /**
     * 处理界面上所有的点击事件
     *
     * @param view
     */
    @Override
    @OnClick({R.id.qiangdan, R.id.btnRight, R.id.et_chufadi, R.id.et_mudidi, R.id.del, R.id.times, R.id.btn_fabu, R.id.tv_mode, R.id.tv_chepai})
    public void onClick(View view) {
        int id = view.getId();

        /***
         * 点击事件开始 判断当前的用户有没有登录
         */
        LoginActivity.startMeAndInitIsLogin(this, Contains.MAIN);
        if (MyApp.getCurrentUser() == null) {
            return;
        }
        //判断当前的用户是否认证
        if (MyApp.getCurrentUser().getAccountDegree() == null) {
            //没有认证信息
            Toastutils.showToast("没有认证信息");
            return;
        }
        if (MyApp.getCurrentUser().getAccountDegree().equals("0")) { //如果状态是0 只是注册 没有完善信息
            //跳转到认证的界面
            startActivity(new Intent(this, IdentificationActivity.class));
            return;
        } else if (MyApp.getCurrentUser().getAccountDegree().equals("1")) {//完善了基本信息
            startActivity(new Intent(this, CarIdentificationActivity.class));
            //跳转到车辆认证的界面
            return;
        } else if (MyApp.getCurrentUser().getAccountDegree().equals("2")) {//完善了车辆信息
            startActivity(new Intent(this, IdentificationActivity.class));
            //跳转到身份认证的界面
            return;
        }

        switch (id) {
            case R.id.qiangdan:

                //抢单
                /**
                 * 点击跳转抢单界面 
                 */
                // TODO: 2017/3/9 如果输入框里面有出发地和目的地 把数据带着过去


                //把车辆的信息带着过去
                strCar = tvChePai.getText().toString().trim();
                Intent intent = new Intent(this, QiangdanActivity.class);
                if (strCar != null || carId != 0) {
                    intent.putExtra("CarNUmber", strCar);
                    intent.putExtra("CarID", carId);
                }

                startActivity(intent);


                break;
            case R.id.btnRight:

                startActivity(new Intent(this, MessageActivity.class));

                break;
            //选择出发点
            case R.id.et_chufadi:
                if (car == null) {
                    Toastutils.showToast("车辆没有选择");
                    return;
                }
                releaseRoute.setCarId(String.valueOf(car.getId()));
                releaseRoute.setDicId(String.valueOf(car.getCarDicId()));
                intent1 = new Intent(this, CityPickerActivity.class);
                intent1.putExtra("releaseRoute", releaseRoute);
                startActivity(intent1);


                break;

//选择目的地
            case R.id.et_mudidi:
                checkMessage();


                break;
            case R.id.del:
                privateEtMudidi.setText("");
                break;

            //时间选择
            case R.id.times:

                checkMessage();







                break;
//发布行程
            case R.id.btn_fabu:


                checkMessage();

                break;
            //车牌
            case R.id.tv_chepai:
                tvChePai.setTextColor(Color.parseColor("#ffffff"));
                tvMode.setTextColor(Color.parseColor("#aaaaaa"));
                tvChePai.setBackgroundResource(R.drawable.shape_left_nomal);
                tvMode.setBackgroundResource(R.drawable.shape_right_nomal);
                if (tvChePai.getText().toString().equals("车牌")) {
                    return;
                }
                if (carList == null) {
                    return;
                }
                if (carList.size() == 1) {
                    return;
                }

                ListViewDialog listViewDialog = new ListViewDialog(this, carList);
                listViewDialog.setOnonRequestFinish(new ListViewDialog.onRequestFinish() {
                    @Override
                    public void requestFinish(String s, int position) {
                        //设置车牌
                        tvChePai.setText(s);
                        //获取车牌的id
                        carId = carListID.get(position);
                        carDicId = carListDicID.get(position);
                        car = cars.get(position);
                    }
                });
                listViewDialog.setCanceledOnTouchOutside(true);
                listViewDialog.show();
                break;
            case R.id.tv_mode:
                tvChePai.setTextColor(Color.parseColor("#aaaaaa"));
                tvMode.setTextColor(Color.parseColor("#ffffff"));
                tvChePai.setBackgroundResource(R.drawable.shape_left);
                tvMode.setBackgroundResource(R.drawable.shape_right);
                if (modeList.size() == 0) {
                    return;
                }
                ListViewDialog tv_modelistViewDialog = new ListViewDialog(this, modeList);
                tv_modelistViewDialog.setOnonRequestFinish(new ListViewDialog.onRequestFinish() {
                    @Override
                    public void requestFinish(String s, int position) {
                        tvMode.setText(s);


                    }
                });
                tv_modelistViewDialog.setCanceledOnTouchOutside(true);
                tv_modelistViewDialog.show();

                break;

        }

    }

    private void checkMessage() {
        if (car == null) {
            Toastutils.showToast("车辆没有选择");
            return;
        }
        releaseRoute.setCarId(String.valueOf(car.getId()));
        releaseRoute.setDicId(String.valueOf(car.getCarDicId()));

        if (privateEtChufadi.getText().toString().trim().equals("")) {
            //没有选择出发地

            intent = new Intent(this, CityPickerActivity.class);
            intent.putExtra("releaseRoute", releaseRoute);
            startActivity(intent);
        } else if (privateEtMudidi.getText().toString().trim().equals("")) {
            //没有选择目的地
            //如果不是空的 携带数据到选择目的地的界面
            releaseRoute.setFromZoneCode(cityCode);
            releaseRoute.setFromAddress(fromaddress);


            intent = new Intent(this, CityPickerActivity.class);
            intent.putExtra("releaseRoute", releaseRoute);
            startActivity(intent);
        } else {
            //选择时间
            releaseRoute.setFromZoneCode(cityCode);
            releaseRoute.setFromAddress(fromaddress);


            intent = new Intent(this, CityPickerActivity.class);
            intent.putExtra("releaseRoute", releaseRoute);
            startActivity(intent);
        }


    }


    Intent intent;


    @Override
    public void requestdataFinish(String catalog, Object bean) {


        Result<List<Car>> result = (Result<List<Car>>) bean;


        if (result.getCode() == 1) {
            //正常处理
            cars = result.getData();
            if (cars != null) {

                carList.clear();
                for (Car car : cars) {

                    carList.add(car.getCarFirstLetter() + car.getCardNumber());
                    carListID.add(car.getId());
                    carListDicID.add(car.getCarDicId());
                    System.out.println("参数的id:" + car.getCarDicId() + "  ---" + car.getId());
                }
                if (carList != null) {
                    tvChePai.setText(carList.get(0));
                    carId = carListID.get(0);
                    carDicId = carListDicID.get(0);
                    car = cars.get(0);
                }
                privateBtnFabu.setText("发布行程");
                isIdentification = false;

            }

        } else if (result.getCode() == 8015) {
            //没有审核通过的车辆
            carList.clear();
            carList.add("没有审核通过的车辆!");
            if (carList != null) {
                tvChePai.setText(carList.get(0));
            }
            privateBtnFabu.setText("认证车辆");
            isIdentification = true;
        }


//        setCarListSpinner();


    }

    @Override
    public void requestdataFailed(IOException e) {

    }
}
